"""
Test that image is not changed when it is read in with ITK as Float pixel type 
and comverted to Unsigned Short pixel type and saved to disk. 
"""

import itk
import connect2
import myImageViewer
import ImageCompare

inputFilename='C:/Lib/JointTrack/branches/bryan/Images/ushortim080-LAT.tif'
ext=inputFilename[inputFilename.find('.'):]
vtk2itk = connect2.vtk2itk()

input_image = itk.Image.F2.New()
output_image = itk.Image.US2.New()

reader = itk.ImageFileReader[input_image].New()

reader.SetFileName(inputFilename)
reader.Update()

caster = itk.CastImageFilter[input_image,output_image].New()
caster.SetInput(reader.GetOutput())
caster.Update()

outputFilename = inputFilename[0:-4]+'_out.png'

writer = itk.ImageFileWriter[output_image].New()
writer.SetInput(caster.GetOutput())
writer.SetFileName(outputFilename)
writer.Write()

#return 0 if they match, 1 otherwise.
comp = ImageCompare.compare(inputFilename,outputFilename)


#Test for positive match
assert comp==0

if comp1==0:
    print "Test Success!"
else:
    print "Test Failure!"

